#include <uview.h>
#include <uview_io.h>
#include <uview_mouse.h>
#include <sys/ioctl.h>
#include <unistd.h>

int uview_set_mouse_status(int fd, uview_mouse_status_t status)
{
    return ioctl(fd, VIEWIO_SETMOUSESTATUS, &status);
}

int uview_set_mouse_status_info(int fd, uview_mouse_status_info_t *info)
{
    if (!info)
        return -1;
    return ioctl(fd, VIEWIO_SETMOUSESTATUSINFO, info);
}

int uview_set_mouse_status_noview(uview_mouse_status_t status)
{
    //open tmp view
    int fd = uview_open_tmp();
    if (fd < 0)
        return -1;
    if (ioctl(fd, VIEWIO_SETMOUSESTATUS, &status) < 0)
    {
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

int uview_set_mouse_stauts_info_noview(uview_mouse_status_info_t *info)
{
    int fd = uview_open_tmp();
    if (fd < 0)
        return -1;
    if (ioctl(fd, VIEWIO_SETMOUSESTATUSINFO, info) < 0)
    {
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

int uview_get_mouse_status(int fd, uview_mouse_status_t *status)
{
    if (!status)
        return -1;
    return ioctl(fd, VIEWIO_GETMOUSESTATUS, status);
}

int uview_get_mouse_status_info(int fd, uview_mouse_status_info_t *info)
{
    if (!info)
        return -1;
    return ioctl(fd, VIEWIO_GETMOUSESTATUSINFO, info);
}

int uview_get_mouse_status_noview(uview_mouse_status_t *status)
{
    if (!status)
        return -1;
    int fd = uview_open_tmp();
    if (fd < 0)
        return -1;
    if (ioctl(fd, VIEWIO_GETMOUSESTATUS, status) < 0)
    {
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

int uview_get_mouse_status_info_noview(uview_mouse_status_info_t *info)
{
    if (!info)
        return -1;
    int fd=uview_open_tmp();
    if(fd<0)
        return -1;
    if(ioctl(fd,VIEWIO_GETMOUSESTATUSINFO,info))
    {
        close(fd);
        return -1;
    }
    close(fd);
    return 0;
}

